#include "IDropletProjector.h"

IDropletProjector::IDropletProjector()
{
	dataSet = false;
	imgData = NULL;
	fileDir.clear();
	fileName.clear();
	fileFormat.clear();
}

IDropletProjector::~IDropletProjector()
{
	SAFE_DELETE(imgData);
}

DS_RESULT IDropletProjector::SetDirectory(std::string dirLocation)
{
	// TODO : Check if directory exists
	fileDir = dirLocation;

	return DS_SUCCESS;
}

DS_RESULT IDropletProjector::LoadFile(std::string fileName)
{
	fileName = fileName;
	std::string filePath = fileDir;
	filePath.append(fileName);

	SAFE_DELETE(imgData);

	imgData = new BMP();
	if(!imgData->ReadFromFile(filePath.c_str()))
	{
		std::cerr << "[WARNING] Failed to open/read image file : " << filePath << std::endl;
		SAFE_DELETE(imgData);
		dataSet = false;
		return DS_WARNING;
	}

	imgHeight = imgData->TellHeight();
	imgWidth  = imgData->TellWidth();

	dataSet = true;
	return DS_SUCCESS;
}

DS_RESULT IDropletProjector::GetPixel(float *crLoc, uint8_t *rgbaVal)
{
	if(!dataSet)
	{
		std::cerr << "[WARNING] No image file loaded. Use IDropletProjector::LoadFile() first." 
			<< std::endl;
		return DS_WARNING;
	}

	if(crLoc[0] >= imgWidth || crLoc[1] >= imgHeight)
	{
		std::cerr << "[WARNING] Requested image location is out-of-bounds."
			<< " Image size is " << imgWidth << " x " << imgHeight << std::endl;
		return DS_WARNING;
	}

	// TODO : Frank Erdesz's BMP Code goes here

	return DS_SUCCESS;
}

DS_RESULT IDropletProjector::GetPixels(
	std::vector<float *> *crLocs, 
	std::vector<uint8_t *> *rgbaVals)
{
	// TODO : Frank Erdesz's BMP Code goes here

	return DS_SUCCESS;
}

DS_RESULT IDropletProjector::GetPixels(float *rcTopLeft, float *rcBottomRight, uint8_t **rgbaVals)
{
	// TODO : Frank Erdesz's BMP Code goes here

	return DS_SUCCESS;
}